import 'package:flutter/material.dart';
import 'package:untitled1/app/widgets/toast/MyToast.dart';

import '../../../res/myColors.dart';
import '../../../utils/utilScreen.dart';
import '../../../widgets/TitleBar.dart';
import '../../../widgets/base_page/BaseStatefulPage.dart';

//佣金详情
class BrokerageInfoPage extends BaseStatefulPage {
  String id;

  BrokerageInfoPage(this.id);

  @override
  BaseStatefulPageState<BaseStatefulPage> createState() {
    return _BrokerageInfoPageState();
  }
}

class _BrokerageInfoPageState extends BaseStatefulPageState<BrokerageInfoPage> {
  @override
  Widget buildPage(BuildContext context) {
    return Scaffold(
      appBar: TitleBar(title: "佣金详情"),
      body: Container(
        width: utilScreen.getScreenWidth(context),
        height: utilScreen.getScreenHeight(context),
        decoration: BoxDecoration(color: Colors.white),
        child: SingleChildScrollView(child: getPage()),
      ),
    );
  }


  Widget getPage() {
    if (1 == 0) {
      return buildPage1();
    }
    return buildPage2();
  }

  //服务费
  Widget buildPage1() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        buildTitle('诉求工种', '保姆', isColorRed: true),
        buildTitle('雇主', '张先生'),
        SizedBox(height: 10),
        buildTitle('经济人', '王武'),
        buildTitle('订单类型', '服务费'),
        SizedBox(height: 10),
        buildTitle('订单编号', 'xxx'),
        buildTitle('订单金额', '1000元'),
        buildTitle('购买数量', '1'),
        buildTitle('缴纳方式', '现金'),
        buildTitle('支付形式', '一次付清'),
        buildTitle('已收金额', '1000元'),
        SizedBox(height: 10),
        Container(
          padding: EdgeInsets.only(left: 10, right: 10),
          child: Text(
            '服务费：1000元',
            style: TextStyle(
              fontSize: 14,
              color: myColors.red,
              fontWeight: FontWeight.bold,
            ),
          ),
        ),

        SizedBox(height: 10),

        ListView.separated(
          shrinkWrap: true,
          // ❗ 让 ListView 高度自适应
          physics: NeverScrollableScrollPhysics(),
          // ❗ 禁止滚动
          itemBuilder: (context, index) {
            return buildItem();
          },
          separatorBuilder: (context, index) {
            return SizedBox(height: 10);
          },
          itemCount: 10,
        ),
      ],
    );
  }

  //区总分佣
  Widget buildPage2() {
    return Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          buildTitle('诉求工种', '保姆', isColorRed: true),
          buildTitle('雇主', '张先生'),
          SizedBox(height: 10),
          buildTitle('订单类型', '区总分佣'),
          buildTitle('分账时间', 'xxx'),
          buildTitle('分账金额', '1000元'),
          buildTitle('退款时间', '1'),
          buildTitle('状态', 'xxx'),
          SizedBox(height: 10),
          Container(
            padding: EdgeInsets.only(left: 10, right: 10),
            child: Text(
              '奖励明细',
              style: TextStyle(
                fontSize: 14,
                color: myColors.c_191919,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),

          SizedBox(height: 10),

          ListView.separated(
            shrinkWrap: true,
            // ❗ 让 ListView 高度自适应
            physics: NeverScrollableScrollPhysics(),
            // ❗ 禁止滚动
            itemBuilder: (context, index) {
              return buildItem();
            },
            separatorBuilder: (context, index) {
              return SizedBox(height: 10);
            },
            itemCount: 10,
          ),
        ]);

  }

  Widget buildTitle(String title, String content, {bool isColorRed = false}) {
    return Container(
      padding: EdgeInsets.only(left: 10, right: 10),
      child: RichText(
        text: TextSpan(
          text: '${title}：',
          style: TextStyle(color: myColors.c_191919, fontSize: 14),
          children: [
            TextSpan(
              text: '${content}',
              style: TextStyle(
                color: isColorRed ? Colors.red : myColors.c_191919,
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget buildItem() {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        buildItemContent('xxx'),
        buildItemContent2('xxx', '查看合同'),
        buildItemContent('xxx'),
      ],
    );
  }

  Widget buildItemContent(String title) {
    return Container(
      margin: EdgeInsets.only(left: 15, right: 15, top: 5),
      child: Text(
        '${title}',
        style: TextStyle(fontSize: 14, color: myColors.c_707070),
      ),
    );
  }

  Widget buildItemContent2(String title, String content) {
    return InkWell(
      onTap: () {
        MyToast.showSystemToast("查看合同");
      },
      child: Container(
        margin: EdgeInsets.only(left: 15, right: 15, top: 5),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(
              '${title}',
              style: TextStyle(fontSize: 14, color: myColors.c_707070),
            ),
            Text(
              '${content}',
              style: TextStyle(fontSize: 14, color: myColors.c_707070),
            ),
          ],
        ),
      ),
    );
  }
}
